package killerqueen.game.objects;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import killerqueen.game.interfaces.GameObject;

import org.jbox2d.common.Vec2;
import org.jbox2d.dynamics.World;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Input;

public class Belt implements GameObject {

	private float minAngularSpeed;
	private float maxAngularSpeed;
	private float angularIncrease;
	private int num_pulleys;
	private float x1;
	private float y1;
	private float x2;
	private float y2;

	List<RotatingCircle> pulleys;
	private Vec2 a;
	private Vec2 b;
	double distance;
	float radius;
	Iterator<RotatingCircle> iterator;

	public Belt() {

	}

	@Override
	public void init(World world, String id) {
		pulleys = new ArrayList<RotatingCircle>();
		iterator = pulleys.listIterator();

		this.a = new Vec2(x1, y1);
		this.b = new Vec2(x2, y2);
		this.distance = distance(a, b);

		int numPulleys = num_pulleys;

		this.radius = (float) ((distance / (numPulleys - 1)) / 2);

		float xDistance = Math.abs(a.x - b.x);
		float yDistance = Math.abs(a.y - b.y);

		for (int i = 1; i <= numPulleys; i++) {
			RotatingCircle pulley = new RotatingCircle();

			float pulleyX = a.x + (xDistance / (numPulleys - 1)) * (i - 1);
			float pulleyY = a.y + (yDistance / (numPulleys - 1)) * (i - 1);

			pulley.setRadius(radius);
			pulley.setX(pulleyX);
			pulley.setY(pulleyY);
			pulley.setMaxAngularSpeed(maxAngularSpeed);
			pulley.setMinAngularSpeed(minAngularSpeed);
			pulley.setAngularIncrease(angularIncrease);

			pulley.init(world, "");

			pulleys.add(pulley);
		}
	}

	public float distance(Vec2 v1, Vec2 v2) {
		return (float) Math.sqrt((v1.x - v2.x) * (v1.x - v2.x) + (v1.y - v2.y)
				* (v1.y - v2.y));
	}

	@Override
	public void input(Input input) {
		// TODO Auto-generated method stub

	}

	@Override
	public void paint(Graphics g) {

		for (RotatingCircle pulley : pulleys) {
			pulley.paint(g);
		}

	}

	@Override
	public void update(long delta) {
		// TODO Auto-generated method stub

	}

	public void setMinAngularSpeed(float minAngularSpeed) {
		this.minAngularSpeed = minAngularSpeed;
	}

	public void setMaxAngularSpeed(float maxAngularSpeed) {
		this.maxAngularSpeed = maxAngularSpeed;
	}

	public void setAngularIncrease(float angularIncrease) {
		this.angularIncrease = angularIncrease;
	}

	public void setNumPulleys(int numPulleys) {
		this.num_pulleys = numPulleys;
	}

	public void setX1(float x1) {
		this.x1 = x1;
	}

	public void setY1(float y1) {
		this.y1 = y1;
	}

	public void setX2(float x2) {
		this.x2 = x2;
	}

	public void setY2(float y2) {
		this.y2 = y2;
	}

	@Override
	public void destroy(World world) {
		// TODO Auto-generated method stub
		
	}

}
